package com.xszx.servlet;

import com.xszx.beans.Orders;
import com.xszx.beans.dto.OrdersDto;
import com.xszx.dao.OrdersDao;
import com.xszx.dao.impl.OrdersDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/GetOrderServlet")
public class GetOrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String username = req.getSession().getAttribute("username").toString();
        int state = Integer.parseInt(req.getParameter("state"));

        OrdersDao orders = new OrdersDaoImpl();
        List<OrdersDto> list = orders.getOrders(username, state);
        double allMoney = orders.getOrderMoney(username);
        int orderNum = orders.getOrderNum(username);

        List<Integer> orderStateNum = orders.getOrderState(username);

        req.setAttribute("shopList", list);
        req.setAttribute("state", state);
        req.setAttribute("num", orderNum);
        req.setAttribute("money", allMoney);
        req.setAttribute("orderStateNum", orderStateNum);

        req.getRequestDispatcher("my_likafu/myOrder.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
